package nowcoder.offer;



/**
 * 翻转单词序列
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @date 2018-08-28 15:13
 */
public class ReverseSentence {

    public String solution(String str){
        String[] s = str.split(" ");
        int len = s.length;
        if (len == 0)
            return str;
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < len-1; i++) {
             res.append(s[len-1-i]).append(" ");
        }
        res.append(s[0]);
        return res.toString();
    }

    public static void main(String[] args) {
        System.out.println(new ReverseSentence().solution(" "));
    }
}
